{% extends "base.html" %}
{% load i18n %}
{% load commonFilters %}

{% comment %}
copyright (c) 2009, paketka@gmail.com et. al
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

	* Redistributions of source code must retain the above copyright notice,
	  this list of conditions and the following disclaimer.

	* Redistributions in binary form must reproduce the above copyright notice,
	  this list of conditions and the following disclaimer in the documentation
	  and/or other materials provided with the distribution.

	* Neither the name of the <ORGANIZATION> nor the names of its contributors
	  may be used to endorse or promote products derived from this software
 	  without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %}

{% block js-links %}
	{{ block.super }}
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery-ui-1.7.custom.min.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jqModal.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jqDnR.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jquery.jqGrid.js"></script>
{% endblock js-links %}

{% block document-ready %}
	{{ block.super }}

	$("#mp-list").jqGrid({
				{% if rangeType %}
				url:'{% url json.views.group_members_json group.slug, rangeType, date.year, date.month, date.day %}',
				{% else %}
				url:'{% url json.views.group_members_json group.slug %}',
				{% endif %}
				datatype: 'json',
				colNames: [	"{% trans "Jméno" %}",
							"{% trans "Příjmení" %}",
							"{% trans "Funkce" %}",
							"{% trans "Posl. klub" %}",
							"{% trans "Věk" %}",
							"{% trans "Volební obvod" %}",
							"{% trans "Nepřítomnost [%]" %}"
						{% if rangeType %}
							,
							"{% trans "Od" %}",
							"{% trans "Do" %}",
							"{% trans "Dnů ve funkci" %}"
						{% endif %}
					],
				colModel :[
					{ name: "name", index: "person__name", width: 120, jsonmap: "name", sortable: true },
					{ name: "surname", index: "person__surname", width:120, jsonmap:"surname", sortable: true },
					{ name: "post", index: "post", width:80, jsonmap:"post", align:"center", sortable: true },
					{ name: "party", index: "group__name", width: "70", align: "center", jsonmap:"party", sortable: true },
					{ name: "age", index: "person__birthDate", width: "30", align: "center", jsonmap:"age", sortable: true },
					{ name: "division", index: "division", width: "100", align: "center", jsonmap:"divName", sortable: true },
					{ name: "absences", index: "absences", width: 70, align: "center", jsonmap: "absences", sortable: true }
				{% if rangeType %}
					,
					{ name: "start", index: "start", width: 70, align: "center", jsonmap: "start", sortable: true },
					{ name: "end", index: "start", width: 70, align: "center", jsonmap: "end", sortable: true },
					{ name: "days", index: "days", width: 70, align: "center", jsonmap: "days", sortable: true }
				{% endif %}
				], 
				pager: $('#mp-pager'),
				jsonReader: {
					root: "rows",
					id: "pk",
					page: "page",
					total: "total",
					records: "records",
					repeatitems: false
				},
				sortname:"person__surname",
				sortorder:"asc",
				rowNum:10,
				rowList:[10,15,20],
				viewrecords:true,
				imgpath:"{{ MEDIA_URL }}/css/jqgrid/themes/basic/images",
				caption:"{{ group.name }} {{ extendedTitle }}",
				width:780,
				toolbar: [true,'top']
	});
	$("#t_mp-list").filterGrid("#mp-list", {
				gridModel: false,
				gridToolBar: false,
				filterModel: [ {
					label: '',
					name: 'filter__exp',
					stype: 'text',
					defval: ''
				} ],
				autosearch: true,
				searchButton: '{% trans "Hledej" %}',
				enableSearch: true
			}
		);

	$("#stat-tab").tabs({
		selected: {{ tabIndex }},
		select: function(event, ui) {
			tabUrls = [
				'{% url psp.views.show_group group.slug, "den", date.year, date.month, date.day %}',
				'{% url psp.views.show_group group.slug, "tyden", date.year, date.month, date.day %}',
				'{% url psp.views.show_group group.slug, "mesic", date.year, date.month, date.day %}',
				'{% url psp.views.show_group group.slug %}',
			];
			window.location.replace(tabUrls[ui.index]);
		}
	});
{% endblock document-ready %}

{% block left-sidebar %}
	{% comment %}
	We want to get rid off poll calendar for MP' complete term overivew.
	Instead of calendar we want to offer visitor the choice of other MP's terms
	{% endcomment %}
	<div class="ui-widget">
		<div class="ui-widget-header">
			<h1>{% trans "Kalendář hlasování" %}</h1>
		</div>
		<div class="ui-widget-content">
			<div class="container">
				{% url json.views.get_meetings_in_month date.year, date.month as events %}
				{% if rangeType %}
					{% url psp.views.show_group group.slug, rangeType, date.year, date.month, date.day as eventDetails %}
				{% else %}
					{% url psp.views.show_group group.slug as eventDetails %}
				{% endif %}
				{% datepicker "meetingPicker" events eventDetails date %}
			</div>
		</div>
	</div>
{% endblock %}

{% block content %}
<div class="ui-widget">
	<div class="ui-widget-header">
		{% if rangeType %}
		<h1>{{ group.name|mf:"group-name" }} {{ extendedTitle }}</h1>
		{% else %}
		<h1>{{ group.name|mf:"group-name" }} [ {{ group.term.getStart }} - {{ group.term.getEnd }} ]</h1>
		{% endif %}
	</div>
	<div class="ui-widget-content">
		<div id="stat-tab">
			<ul>
				<li><a href="main-tab">{% trans "Dnes" %}</a></li>
				<li><a href="main-tab">{% trans "Týden" %}</a></li>
				<li><a href="main-tab">{% trans "Měsíc" %}</a></li>
				<li><a href="main-tab">{% trans "Období" %}</a></li>
			</ul>

			<div id="main-tab">
				<div class="ui-widget">
					<div class="ui-widget-content">
							<div class="left">
								{% blocktrans %}
								<p class="tab-par">
									Ve skupině se prostřídalo {{ memberCount }} poslanců.
									Průměrný věk skupiny dosáhl {{ avgAge }} let.
								{% endblocktrans %}
							{% if not partyPie %}
							{% with group.getPartyName as partyName %}
							{% blocktrans %}
									Horní graf znázorňuje celkovou absenci poslanců partajního
									klubu {{ partyName }} ve zvoleném období.
								</p>
							{% endblocktrans %}
							</div>
							<div class="right">
								<p class="par-tab">
									{{ absencesPie.img|safe|mf:"group-absences-pie" }}
								</p>
							</div>
							<div class="clear">
							</div>
							<div class="left">
							{% blocktrans %}
								<p class="tab-par">
									Dolní graf se pokouší vyjádřit disciplinu při
									hlasování. Slovem disciplina zde máme na mysli
									poměr poslanců, kteří hlasují shodně s většinou
									členů klubu {{ partyName }}. Při výpočtu grafu
									absence poslanců <strong>nebyly</strong> zanedbány.
								</p>
							{% endblocktrans %}
							</div>
							<div class="right">
								<p class="par-tab">
									{{ disciplinePie.img|safe|mf:"group-discipline-pie" }}
								</p>
							</div>
							<div class="clear">
							</div>
							{% endwith %}
							{% else %}
							{% with group.name as groupName %}
							{% blocktrans %}
									První graf vpravo poskytuje přehled o partajním složení
									poslanecké skupiny {{ groupName }}.
								</p>
							</div>
							{% endblocktrans %}
							<div class="right">
								<p class="par-tab">
									{{ partyPie.img|safe|mf:"group-party-pie" }}
								</p>
							</div>
							<div class="clear">
							</div>
							{% blocktrans %}
							<div class="left">
								<p class="tab-par">
								Druhý graf zkoumá celkovou absenci členů této skupiny.
								</p>
							</div>
							{% endblocktrans %}
							<div class="right">
								<p class="par-tab">
									{{ absencesPie.img|safe|mf:"group-absences-pie" }}
								</p>
							</div>
							<div class="clear">
							</div>
							{% blocktrans %}
							<div class="left">
								<p class="tab-par">
									A konečně tu máme poslední graf. Ten se pokouší
									vyjádřit disciplinu při hlasování. Slovem
									disciplina zde máme na mysli poměr poslanců,
									kteří hlasují shodně s většinou členů klubu {{ groupName }}.
									Při výpočtu grafu absence poslanců <strong>nebyly</strong> zanedbány.
								</p>
							</div>
							{% endblocktrans %}
							<div class="right">
								<p class="par-tab">
									{{ disciplinePie.img|safe|mf:"group-discipline-pie" }}
								</p>
							</div>
							<div class="clear">
							</div>
							{% endwith %}
							{% endif %}
						</div>
						<div class="clear"></div>
						<table id="mp-list" class="scroll" cellpadding="0" cellspacing="0">
						</table>
						<div id="mp-pager" class="scroll" style="text-align:center;">
						</div>
					</div><!-- ui-widget-content -->
				</div><!-- ui-wdiget -->
				{% block main-tab %}
				{% endblock %}
			</div> <!-- end of main-tab -->
		</div>
	</div>
</div>

{% endblock content %}
